from django.shortcuts import render, redirect

# Create your views here.
from product.models import ProductModel
from type.models import ProductTypeModel


def start(request):
    # request.session['language'] = 'zh_CN'
    return redirect('/index/default')


def index(request, pk):
    if request.method == 'GET':
        product_types = ProductTypeModel.objects.all()
        if pk == 'default':
            type_title = ProductTypeModel.objects.first()
            products = ProductModel.objects.filter(type=product_types.first())
        else:
            type_title = ProductTypeModel.objects.get(pk=pk)
            products = ProductModel.objects.filter(type=pk)

        return render(request, f'{request.session.get("language")}/index.html', locals())
    pass


# 产品详情
def product(request, pk):
    if request.method == 'GET':
        product = ProductModel.objects.filter(pk=pk).get()
        return render(request, f'{request.session.get("language")}/product.html', locals())
